﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace PubSubGeneric.WCFContracts
{
    internal static class KnownTypesProvider
    {
        private static List<Type> Types;
        public static IEnumerable<Type> GetKnownTypes(ICustomAttributeProvider provider)
        {
            if (Types == null)
                LoadTypes();
            return Types;
        }

        private static bool LoadTypes()
        {
            IEnumerable<string> keys = System.Configuration.ConfigurationManager.AppSettings.AllKeys.Where(p => p.StartsWith("PubSub.WCF.KnownTypes"));
            Types = new List<Type>();
            foreach (var key in keys)
            {
                try
                {
                    Types.Add(Type.GetType(System.Configuration.ConfigurationManager.AppSettings[key]));
                }
                catch (Exception ex)
                {
                }
            }
            return true;
        }
    }
}
